package com.ruoyi.sl.service.impl;

import java.util.List;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.sl.mapper.SlWorkshopMapper;
import com.ruoyi.sl.domain.SlWorkshop;
import com.ruoyi.sl.service.ISlWorkshopService;

/**
 * 车间Service业务层处理
 * 
 * @author admin
 * @date 2024-06-05
 */
@Service
public class SlWorkshopServiceImpl implements ISlWorkshopService 
{
    @Autowired
    private SlWorkshopMapper slWorkshopMapper;

    /**
     * 查询车间
     * 
     * @param workshopId 车间主键
     * @return 车间
     */
    @Override
    public SlWorkshop selectSlWorkshopByWorkshopId(Long workshopId)
    {
        return slWorkshopMapper.selectSlWorkshopByWorkshopId(workshopId);
    }

    //根据部门ID查找车间
    @Override
    public SlWorkshop selectSlWorkshopByDeptId(Long deptId){
        return slWorkshopMapper.selectSlWorkshopByDeptId(deptId);
    }
    /**
     * 查询车间列表
     * 
     * @param slWorkshop 车间
     * @return 车间
     */
    @Override
    public List<SlWorkshop> selectSlWorkshopList(SlWorkshop slWorkshop)
    {
        return slWorkshopMapper.selectSlWorkshopList(slWorkshop);
    }

    /**
     * 根据模块ID查询所有车间
     */
    @Override
    public List<SlWorkshop> selectSlWorkshopListByModuleId(Long moduleId)
    {
        return slWorkshopMapper.selectSlWorkshopListByModuleId(moduleId);
    }

    /**
     * 根据车间ID查询车间下是否有子元素
     */
    @Override
    public Boolean checkWorkshopMemberNum(Long workshopId){

        return slWorkshopMapper.checkWorkshopMemberNum(workshopId) > 0?false:true;
    }

    /**
     * 校验车间名是否存在
     *
     * @param slWorkshop 车间信息
     * @return
     */
    @Override
    public Boolean checkWorkshopName(SlWorkshop slWorkshop){
        Long workshopId = StringUtils.isNull(slWorkshop.getWorkshopId()) ? -1L : slWorkshop.getWorkshopId();
        SlWorkshop workshop = slWorkshopMapper.selectSlWorkshopByWorkshopName(slWorkshop);
        if (StringUtils.isNotNull(workshop) && workshop.getWorkshopId().longValue() != workshopId.longValue())
        {
            return false;
        }
        return true;
    }

    /**
     * 新增车间
     * 
     * @param slWorkshop 车间
     * @return 结果
     */
    @Override
    public int insertSlWorkshop(SlWorkshop slWorkshop)
    {
        slWorkshop.setCreateTime(DateUtils.getNowDate());
        return slWorkshopMapper.insertSlWorkshop(slWorkshop);
    }

    /**
     * 修改车间
     * 
     * @param slWorkshop 车间
     * @return 结果
     */
    @Override
    public int updateSlWorkshop(SlWorkshop slWorkshop)
    {
        slWorkshop.setUpdateTime(DateUtils.getNowDate());
        return slWorkshopMapper.updateSlWorkshop(slWorkshop);
    }

    /**
     * 批量删除车间
     * 
     * @param workshopIds 需要删除的车间主键
     * @return 结果
     */
    @Override
    public int deleteSlWorkshopByWorkshopIds(Long[] workshopIds)
    {
        return slWorkshopMapper.deleteSlWorkshopByWorkshopIds(workshopIds);
    }

    /**
     * 删除车间信息
     * 
     * @param workshopId 车间主键
     * @return 结果
     */
    @Override
    public int deleteSlWorkshopByWorkshopId(Long workshopId)
    {
        return slWorkshopMapper.deleteSlWorkshopByWorkshopId(workshopId);
    }
}
